﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibraryOfBooks
{
    class Library
    {
        private string name;
        List<Books> listOfBooks = new List<Books>();

        public Library(string name)
        {
            this.name = name;
        }

        public void AddBook(string title, string author, string publisher,
            string year, string isbn)
        {
            listOfBooks.Add(new Books(title, author, publisher, year, isbn));
        }

        public void Display()
        {
            Console.WriteLine("Books in library {0} : ", name);
            foreach(var book in listOfBooks)
            {
                Console.WriteLine("\t" + book.Title + " by " + book.Author);
            }
        }

        public void DeleteByAuthor(string author)
        {
            for (int i = listOfBooks.Count - 1; i >= 0; i--)
            {
                if (listOfBooks[i].Author.Equals(author))
                {
                    listOfBooks.RemoveAt(i);
                }
            }
        }

        public void DeleteByTitle(string title)
        {
            for (int i = listOfBooks.Count - 1; i >= 0; i--)
            {
                if (listOfBooks[i].Title.Equals(title))
                {
                    listOfBooks.RemoveAt(i);
                }
            }
        }

        public void SearchByAuthor(string author)
        {
            foreach (var book in listOfBooks)
            {
                if (book.Author.Equals(author))
                {
                    Console.WriteLine("\t" + book.Title);
                }
            }
        }

        public void SearchByTitle(string title)
        {
            foreach (var book in listOfBooks)
            {
                if(book.Title.Equals(title))
                {
                    Console.WriteLine("\t" + book.Title + " by" + book.Author);
                }
            }
        }
    }
}
